<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>

    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <script src="js/common.js"></script>
</head>
<body>
<div id="myDiv">

</div>
<script type="text/javascript">
    new Vue({
        el:"#callback",
        mounted(){
            // 解析参数对象
            let url = location.href;
            // 解析URL地址参数的工具函数
            let paramObj = parseUrlParams2Obj(url);

            // 从当前页面地址中获取code，并组装为JSON
            let params = {"code":paramObj.code};
            console.log(params)
            //发起微信登录请求
            this.$http.post("/login/wechat",params)
                .then(result=>{
                    console.log(result)
                    result = result.data;
                    if(result.success){ // 说明用户微信与账号已经绑定，免密登录成功
                        // 登录成功提示
                        // alert(result.msg);
                        // 登录成功需要将用户信息放入到localStorage
                        let {token, logininfo} = result.resultObj;
                        localStorage.setItem("token", token);
                        // 需要转换成JSON字符串进行存储，因为localStorage不能存储对象
                        localStorage.setItem("logininfo", JSON.stringify(logininfo));
                        // 跳转到前台首页
                        location.href = "index.html";
                    }else{ // 没有绑定账号，跳转到
                        // 账号绑定页面,需要在后面拼接accessToken、openId
                        debugger
                        let binderUrl = "http://bugtracker.itsource.cn/binder.html"+result.resultObj
                        // 跳转到账号绑定页面
                        location.href = binderUrl;
                    }
                })
                .catch(result=>{
                    alert("系统繁忙，请稍后重试！");
                    console.log(result);
                })
        }
    });
</script>
</body>
</html>